using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

using EntLibEC.Cmn;
using EntLibEC.Info.Basic;
using EntLibEC.Biz.Basic;

namespace EntLibEC.View.Cmn
{
	/// <summary>
	/// Summary description for ShipType.
	/// </summary>
	public class ShipType : Control, INamingContainer 
	{
		private DropDownList ddlShipType = new DropDownList();

		public void BindShipType(bool isAll)
		{
			SortedList sl = ASPManager.GetInstance().GetShipTypeList(false);
			BindDll(sl, isAll);
		}

        public void BindShipType(bool isAll, bool isOnlineShow)
        {
            SortedList sl = ASPManager.GetInstance().GetShipTypeList(isOnlineShow);
            BindDll(sl, isAll);
        }

		private void BindDll(SortedList sl, bool isAll)
		{
			ddlShipType.Items.Clear();
			if ( sl != null && sl.Count != 0 )
			{
				foreach(ShipTypeInfo item in sl.Values)
				{
					ddlShipType.Items.Add(
						new ListItem(item.ShipTypeName, item.SysNo.ToString()) );
				}
			}
			if ( isAll )
				ddlShipType.Items.Insert(0, new ListItem( AppConst.AllSelectString, AppConst.IntNull.ToString() ));
		}

		public void BindShipTypeByArea(int areaSysNo)
		{
			SortedList sl = ASPManager.GetInstance().GetShipTypeListByArea(areaSysNo);
			BindDll(sl, true);
		}
		private bool _autoPostBack;
		public bool AutoPostBack
		{
			get
			{
				return _autoPostBack;
			}
			set
			{
				_autoPostBack = value;
			}

		}

		protected override void OnInit(EventArgs e)
		{
			if ( AutoPostBack)
			{
				ddlShipType.AutoPostBack = true;
				ddlShipType.SelectedIndexChanged += new System.EventHandler(ddl_SelectedIndexChanged);
			}
			Controls.Add(ddlShipType);
			base.OnInit(e);
		}

		public void ddl_SelectedIndexChanged(object sender, System.EventArgs e)
		{

			if (SelectedIndexChanged != null)
				SelectedIndexChanged(this, EventArgs.Empty);
		}


		public int ShipTypeSysNo
		{
			get
			{
				return Convert.ToInt32(ddlShipType.SelectedItem.Value);
			}
			set
			{
				if(ddlShipType.Items.FindByValue(value.ToString())!=null)
					ddlShipType.SelectedIndex = ddlShipType.Items.IndexOf(ddlShipType.Items.FindByValue(value.ToString()));
				else
					ddlShipType.SelectedIndex = ddlShipType.Items.IndexOf(ddlShipType.Items.FindByValue(AppConst.IntNull.ToString()));
			}
		}

		public bool Enabled
		{
			set
			{
				ddlShipType.Enabled = value;
			}
		}

		public event EventHandler SelectedIndexChanged;
	}
}
